<template>
  <div class="newsinfo">
    <h3 class="title">{{newinfo.title}}</h3>
    <p class="label">
      <span>发表时间：{{newinfo.add_time|dataFormat}}</span>
      <span>点击:{{newinfo.click}}次</span>
    </p>

    <hr />

    <!-- 内容 -->
    <div class="wordbody" v-html="newinfo.content"></div>
  
  <!-- 评论子组件 -->
  <comment :id="this.id"></comment>
  </div>
</template>

<script>
import { Toast } from "mint-ui";

//导入评论子组件
import comment from "../soncomponent/comment.vue";

export default {
  data() {
    return {
      //将url地址中传递过来的id值，挂载到data上
      id: this.$route.params.id,
      newinfo: {}
    };
  },
  created() {
    this.getnewsinfo();
  },
  methods: {
    getnewsinfo() {
      //获取新闻详情
      this.$http.get("api/getnew/" + this.id).then(result => {
        if (result.body.status === 0) {
          this.newinfo = result.body.message[0];
        } else {
          Toast("新闻获取失败");
        }
      });
    }
  },
  components: {
    comment
  }
};
</script>

<style lang="scss">
.newsinfo {
  padding: 0 6px;
  .title {
    font-size: 16px;
    text-align: center;
    margin: 10px 0;
    color: red;
  }
  .babel {
    font-size: 12px;
    color: lightskyblue;
    display: flex;
    justify-content: space-between;
  }
  .wordbody {
    img {
      width: 100%;
    }
  }
}
</style>